const { request } = require('../utils/https.js')
const { APP_ID, APP_SECRET } = require('../config/config_dev')

// 获取微信access_token
const getAccessToken = () => {
    return request({
        url: 'https://api.weixin.qq.com/cgi-bin/token',
        method: 'get',
        params: {
            grant_type: 'client_credential',
            appid: APP_ID,
            secret: APP_SECRET,
        }
    })
}


// 微信小程序手机号码验证登录
const wxLogin = ({ token, code }) => {
    return request({
        url: `https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=${token}`,
        method: 'post',
        data: {
            code
        }
    })
}

module.exports = {
    getAccessToken,
    wxLogin
}